Skip to content

fix(permissions): one allow rule per script, * only at the end (#780) - #781

Merged
MendixMau merged 4 commits into
masterfrom
triage/780-permission-rules
Nov 16, 2026
Merged

MendixMau merged 4 commits into
masterfrom
triage/780-permission-rules

Conversation

@MendixMau

Copy link
Copy Markdown
Owner

Fixes #780

Direct lane

What changed and why (one paragraph): bin/install-claude-permissions.sh wrote allow rules such as Bash(./bin/*.sh:*), Bash(~/.mxcli/mxbuild/*/modeler/mx:*) and Bash($TOOLKIT_ROOT/bin/*.sh:*). Each one mixes a * with the trailing :*, and Claude Code 2.1.325 does not match such a rule as the installer meant. claude doctor reports each one as "matched as a literal prefix (the * is not expanded) and will likely never match". A real claude -p run under master's rules was denied both ./bin/status.sh and ./bin/status.sh --brief. That is worse than the issue's reading, which was that only bare calls prompt.

The installer now writes one space-form rule per script that exists, with the * only at the end:

  • Shared settings.json: Bash(./bin/<name>.sh *), Bash(bin/<name>.sh *) and Bash(bash bin/<name>.sh *) for each project bin/*.sh. The exec.sh entries are always present.
  • Local settings.local.json: Bash(<toolkit>/bin/<name>.sh *) and Bash(bash <toolkit>/bin/<name>.sh *) for each toolkit script. Also one mx rule per installed ~/.mxcli/mxbuild/<ver>/modeler/mx[.exe], in both the ~ and the absolute spelling.
  • Other allow rules: Bash(./mxcli *), Bash(mxcli *) and the project-profile allow rules (npm install, git add, …) move to the space form. With a single wildcard this is exactly equivalent.
  • Deny and ask rules: unchanged.

Migration:

  • It goes through the existing sidecar. A re-install removes the old entries this script added and never touches foreign ones.
  • --check (and so sync-project.sh) now names the entries the next install will remove. That listing alone never changes the exit code.

Other changes:

  • The fixture exposed a latent bug, now fixed. When an install run pruned an entry, it dropped every addition in that same run, because the prune rebound perms["allow"] away from the list the additions were appended to.
  • The header's RULE SYNTAX block is rewritten and cites both doc sections.
  • doctor.sh greps the new "Bash(./bin/exec.sh *)" spelling, so an old install reads "missing the safe-wrapper entries" and gets the re-run hint.

Impact

Row Answer
Process No new gate or block. sync-project.sh's existing permission --check WARN now fires once on every project installed before this change: the new per-script entries are missing until install-harness-permissions.sh <project> is re-run, and the output lists the old entries that the re-run removes. A script installed later, or a new mxbuild version, also shows as missing until the next re-run, the same way any missing entry does today.
Dependencies Touches bin/install-claude-permissions.sh, bin/doctor.sh (one grep string), bin/init-project.sh (comment only) and the fixture. No _common.sh, exec.sh or skill-routing.tsv changes. New reads: <project>/bin/*.sh (producer: init-project/sync-project install from install-manifest.sh before this script runs at init), <toolkit>/bin/*.sh, and $HOME/.mxcli/mxbuild/*/modeler/mx (producer: mxcli setup mxbuild / doctor.sh --install; none installed is fine). Independent of #775: both touch bin/doctor.sh (different lines, which auto-merge) and CHANGELOG (keep both lines).
Context cost none: no routed or always-loaded file touched
Behaviour n/a: scripts only
Runtime Install 0.12 s → 0.14 s and --check 0.13 s → 0.16 s, on a project with all 56 project-bin .sh installed and the project profile (Linux container). Nothing per exec. The shared settings.json allow list grows 22 → 183 entries (168 script rules) and the local one 2 → 114, which is the issue's accepted cost of about 3 per script.

Time cost: per project (install/sync check) · +0.03 s on a Linux container · can force rework: n · offset: removes the permission prompt on every toolkit-script and mx call, and the doctor/startup warning rows

Field evidence (claude 2.1.325, 2026-11-16; the maintainer authorised the model calls and asked for this proof before any fix):

The test used a throwaway project with an executable bin/status.sh that prints ok. Rules were master's installer output, passed through --settings; without it, -p prints Ignoring 9 permissions.allow entries … this workspace has not been trusted. The new-rules control shows that --settings is honored. Command: claude -p … --permission-mode default --output-format json --max-turns 3.

rules command outcome permission_denials
master's ./bin/status.sh "This command requires approval", not run 1
master's ./bin/status.sh --brief "This command requires approval", not run 1
Bash(./bin/status.sh *) ./bin/status.sh ok []
Bash(./bin/status.sh *) ./bin/status.sh --brief ok []

claude doctor (no model call), with the workspace trusted through a scratch HOME:

  • Master-installed project: a "Permission rules that may not work as written" section with 6 rows (4 shared, 2 local).
  • Branch-installed project: no such section.
  • Master install with profile project, re-installed by this branch: no such section. The re-install removed the 19 old entries.

No startup warning appeared on stderr in -p mode. The interactive banner row was not observed, because there is no TTY here.

Fixture: tests/wave2/test-install-claude-permissions.sh. The T1–T6 expectations are updated to the new strings, and a new T12 checks that:

  • no allow rule has a * before its final *;
  • bare and with-argument calls match under the documented rules (./bin/gate-check.sh, bin/status.sh, bash bin/doctor.sh, toolkit scripts by absolute path, mx in both spellings), and ./bin/gate-check.shx does not;
  • mxbuild rules stay local;
  • a master-shaped install migrates: old wildcard entries are removed from both files, foreign Bash(npm test *) and Bash(make *) are kept, and --check names the old entries beforehand.

Results:

  • master's script (origin/master c3c8a30): PASS=186 FAIL=13
  • this branch: PASS=199 FAIL=0

Other checks:

  • Other fixtures that target the changed files: test-look-hook-cwd.sh 9/0 and test-look-ledger-hook-repair.sh 13/0.

  • Not run, checked by inspection: test-model-stamp.sh T8 (refused by the session's auto-mode classifier; the deny list it asserts is unchanged) and the test-file-bugs.sh permissions check (its Python ran standalone against the new file and exits 0).

  • bin/check-scripts.sh, the leak guard and bin/check-portability.sh are clean.

  • No client data anywhere in the diff

  • Size cap: 5 files, ~140 non-fixture lines

  • Test tier reached: fixture plus a real Claude Code run (the field proof above)

  • For a changed instrument: the golden input is master's real installer output. Layouts: .claude/ and bin/ sit at the project root in both. Platforms: bash 3.2-safe, and mx.exe is included for Git Bash

  • For a new skill: n/a

  • CHANGELOG.md line appended, crediting the reporters

  • New bug entries: n/a

Review: pending independent review


Generated by Claude Code

install-claude-permissions.sh wrote Bash(./bin/*.sh:*) and friends. A `*`
mixed with the trailing `:*` is matched as a literal prefix: claude doctor
2.1.325 flags each such rule, and a real `claude -p` run was denied both
`./bin/status.sh` and `./bin/status.sh --brief` under master's rules, while
Bash(./bin/status.sh *) ran both.

Now: one space-form rule per script that exists (project bin/ shared,
toolkit bin/ by absolute path local), one mx rule per installed mxbuild
version (local, `~` and absolute spellings). Old entries go through the
existing sidecar prune; --check names them. The prune rebound the allow
list, which dropped every addition in the same run; it now edits in place.
Project-profile allow rules use the space form; deny/ask are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HXpQSjXefSNicGGqP4aiSC
@MendixMau

Copy link
Copy Markdown
Owner Author

Review: MERGE-AFTER-FIX. The fix is correct and needed, and existing installs migrate cleanly. But it turns a dead allow list into a live one, so an agent can now run install-claude-permissions.sh --profile full (which adds a bare Bash allow) with no prompt.

Value: Fixes #780 as reported, and I reproduced it. claude doctor 2.1.325 in a trusted scratch HOME lists 6 "may not work as written" rows for a master install. After a re-install from this branch it shows no such section. One rule per script with * only at the end is the docs' recommendation, so this is not overbuilt. The in-place prune (bin/install-claude-permissions.sh:507, perms[key][:]) is a real fix: allow (:491) aliases perms["allow"], so before this change a pruning run appended its additions to an orphaned list.

Regression risk:

  • Migration is safe. I installed on master (profile project, 56 project scripts) and re-installed from the branch. Exactly 19 entries were removed, all of them from the sidecar. Foreign entries survive. DENY/ASK are byte-identical.
  • New effective permissions. The old wildcards never matched; now every toolkit bin/*.sh runs unprompted by absolute path (:212-215). That includes install-claude-permissions.sh --profile full, which adds a bare Bash allow (:289-291), and permission-profile.sh --set / interview-mode.sh --set. Together that is a self-escalation path with no prompt, and these scripts are the "a person's decision" class the deny list exists for.
  • sync output. On a project installed before [bug] install-claude-permissions.sh writes allow rules that mix * with trailing :* — bare script calls still prompt, and every wrapper rule raises a startup warning #780, sync's existing WARN prints about 300 lines once. It warns again after any toolkit pull that adds a bin/*.sh. Noisy, but acceptable. Exit codes and parsed strings are unchanged.
  • bash 3.2. An empty ENTRIES_LOCAL is guarded (:648). Globs that match nothing are skipped by [ -f ]. check-portability.sh is clean.

Correctness:

  • Bug in --hooks-only --check. entries is empty in that mode, so the new stale block (:400-404) prints every allow entry in the sidecar as "the next install removes". That was 165 false lines in my run.
  • Fixture matcher. T12's match() is the author's own model of the matcher, so it partly checks itself. The field claude -p run and claude doctor cover the real matcher.
  • Fixtures (detached worktree): test-install-claude-permissions 199/0, test-model-stamp 35/0, test-file-bugs 218/0.
  • Minor. The sourced libraries _common.sh and _claims.sh get rules too.

Context cost: 66271 → 66271 words (measured).

Time cost: install/sync check only, --check 0.115 s → 0.149 s. Nothing runs per exec.

Exact fixes required:

  1. Leave the permission-rewriting scripts out of _script_rules, so they prompt: at minimum install-claude-permissions.sh, install-harness-permissions.sh and permission-profile.sh. Add a T12 assertion that no allow rule names them.
  2. Skip the stale listing when MXTK_HOOKS_ONLY=1 (:400).
  3. (Optional) Skip _*.sh in _script_rules.

Generated by Claude Code

…ing; --hooks-only --check lists no stale entries

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HXpQSjXefSNicGGqP4aiSC
@MendixMau

Copy link
Copy Markdown
Owner Author

Review fixes pushed in 7ef3f99.

  1. Decision-recording scripts keep prompting. These scripts record a person's decision, so _script_rules now skips them: install-claude-permissions.sh, install-harness-permissions.sh, permission-profile.sh, exec-approval.sh and interview-mode.sh. It also skips the sourced _*.sh libraries. The reviewer named the first three; I added exec-approval.sh and interview-mode.sh because they set the agent's own exec autonomy and interview mode. A T12 assertion checks that no allow rule names any of them.
  2. No false stale list under --hooks-only --check. That mode no longer lists stale allow entries. T12 covers it.
  3. CHANGELOG names the excluded scripts.

Fixture tests/wave2/test-install-claude-permissions.sh:

Script Result Notes
PR's previous script (5aa7879) PASS=201 FAIL=2 Both new checks fail.
Fixed script PASS=191 FAIL=0 The total drops because the expected local list no longer includes the excluded scripts.

Needs a re-review before merge.


Generated by Claude Code

@MendixMau

Copy link
Copy Markdown
Owner Author

Review: MERGE-AFTER-FIX (re-review). The fix commit 7ef3f99 is correct, and all three requested fixes landed. One unprompted path to bare Bash is still open: init-project.sh keeps its new allow rule, and it calls install-harness-permissions.sh with whatever profile PROJECT.md names.

Value: Fixes #780 as reported. The fix commit leaves the five decision-recording scripts and _*.sh out of _script_rules (bin/install-claude-permissions.sh:195-198), and --hooks-only gets an empty stale list (:404-405).

Regression risk:

  • Escalation path.
    • Under the default project profile, Edit(/**) lets the agent change PROJECT.md to Permission profile: full.
    • It can then run <toolkit>/bin/init-project.sh <proj>, which now has an allow rule.
    • That script calls install-harness-permissions.sh with no profile (bin/init-project.sh:453-454).
    • permission-profile.sh:76-90 reads PROJECT.md whenever .mxtk/permission-profile is absent, and init never writes that file.
    • I reproduced the last step: with PROJECT.md set to full and no state file, the harness installer wrote bare "Bash", "Edit" and "Read".
    • On master the init rule never matched, so this path is new.
  • The five exclusions break no flow. The read calls (wiring-item3.sh:33, interview-protocol.md:25) still prompt, exactly as on master. exec.sh and interview-gate.sh call these scripts as subprocesses, which the harness does not gate.
  • Exit codes and parsed strings are unchanged. check-portability.sh passes. No conflict with origin/master.

Correctness: The new T12 assertions test what they claim.

  • test-install-claude-permissions 191/0
  • test-model-stamp 35/0
  • test-file-bugs 218/0

All three ran in a detached worktree. Minor: install-claude-hooks.sh is still allowed. It grants no permission, so this can wait for a follow-up.

Context cost: 66271 → 66271 words (measured).

Exact fixes required:

  1. Add init-project.sh to the exclusion case, to EXPECTED_LOCAL and to the T12 grep.
  2. (Follow-up, not blocking) Let read-only exec-approval.sh <proj> and interview-mode.sh --explain run unprompted, and make --set prompt (an ask rule).

Generated by Claude Code

…missions from PROJECT.md's profile)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HXpQSjXefSNicGGqP4aiSC
@MendixMau

Copy link
Copy Markdown
Owner Author

Review: MERGE. Fix commit 7aeefab is correct: init-project.sh no longer gets an allow rule, and no other allowed script writes a permission or calls a permission setter. One follow-up: install-claude-hooks.sh still writes user-global hooks without a prompt.

Value: Fixes #780 as reported. 7aeefab adds init-project.sh in three places:

  • the exclusion case (bin/install-claude-permissions.sh:199), with the reason in a comment;
  • EXPECTED_LOCAL;
  • the T12 grep (tests/wave2/test-install-claude-permissions.sh:442).

T12 builds its rules from the real toolkit bin/, so the new grep would have failed on 7ef3f99.

Regression risk: The only behaviour change is that <toolkit>/bin/init-project.sh prompts again, as it did on master. A sweep of every script that still gets an allow rule found:

  • Setters: none calls permission-profile.sh, exec-approval.sh or interview-mode.sh with --set.
  • Installers: only sync-project.sh calls them. Line :1602 runs --check, which is read-only. Lines :1619-1627 run --hooks-only, which adds no allow entries and only after --consent-check passes.
  • Sourced project files: no allowed script sources a project file (stack.env, .mxtk/*).
  • wire-agents.sh:404-461: adds nothing new, since Bash(./mxcli *) already lets an agent run ./mxcli init directly.
  • Follow-up: install-claude-hooks.sh (allowed) writes ~/.claude/settings.json hooks that fire in every repo. It grants no permission, but its header calls it a person's decision, so it belongs in the exclusion case.
  • Inherent limit (noted, not this PR): under Edit(/**) an agent can rewrite an allowed project bin/*.sh and run it unprompted.

There is no merge conflict with origin/master.

Correctness: No bugs. Results in a detached worktree:

  • test-install-claude-permissions: 189/0
  • test-model-stamp: 35/0
  • test-file-bugs: 218/0

Context cost: 66271 → 66271 words (measured).

Time cost: none per build row; only install and sync --check are affected.


Generated by Claude Code

@MendixMau
MendixMau merged commit 1e0c38a into master Nov 16, 2026
2 checks passed
MendixMau added a commit that referenced this pull request Nov 16, 2026
…stop allowing install-claude-hooks.sh (#782) (#785)

Review: MERGE — no ordinary spelling of a state-changing call escapes the ask rules; migration verified on a real #781-shaped install; proven on claude 2.1.325

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HXpQSjXefSNicGGqP4aiSC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants